﻿namespace NTLib.Core.Hash
{
    using System;

    /// <summary>
    /// implement the cantor hash to create a unique interger from two other.
    /// </summary>
    public class CantorHash
    {
        #region Methods

        /// <summary>
        /// Hashes the couple of int
        /// </summary>
        public static Int32 Hash(Int32 x, Int32 y)
        {
            return (Int32)(0.5d * ((double)x + (double)y) * ((double)x + (double)y + 1) + (double)y);
        }

        #endregion
    }
}
